<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>应聘列表</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/order/get_work_frm.css" />
    <style>
        .btn {
            width: 3.5rem;
            margin-left: 0.2rem;
            line-height: 0.8rem;
            line-height: 0.8rem;
        }

        .huizhang {
            color: #fff;
            padding: 0.05rem 0.2rem;
            border-radius: 0.2rem;
        }

        .iconimg {
            width: 0.6rem;
            display: inline-block;
        }

        .failure {
            margin-right: 0.5rem;
            font-size: 0.6rem;
            color: #999;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="tab-content">
            <div v-for="o,i in list" style="border-bottom:1px solid #eeeeee;margin-bottom:1rem;">
                <div class="aui-list" @click="openInfo(o)">
                    <div class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-title aui-ellipsis-1">{{o.user_introduction}}</div>
                        </div>
                    </div>
                    <div class="aui-list-item">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-media">
                                <img :src="o.headimgurl" onerror='this.src="../../../image/portrait.png"'>
                            </div>
                            <div class="person_info">
                                <div><img src="../../../image/icon/menu02-1.png" class="iconimg" alt=""> <span>联系人：{{o.user_name}}</span></div>
                                <div> <img src="../../../image/icon/daohang.png" class="iconimg" alt=""><span>项目地点：{{o.region}}</span></div>
                                <div><img src="../../../image/icon/zhuangtai.png" class="iconimg" alt="">
                                    <span class="huizhang" v-if="o.is_work===1" style="background:#F3AD17;">忙碌中</span>
                                    <span class="huizhang" v-else style="background:#0689FB;">找活中</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="btn-group" style="justify-content: space-between;align-items:center;line-height2.25rem;height:2.25rem;">
                    <div style="font-size:0.6rem;color:#C1C1C1;">
                        <span v-if="o.user_type===2">属性：已认证工人</span>
                        <span v-else>属性：普通工人</span>
                    </div>
                    <div style="display:flex;align-items:center;font-size:0.6rem;">
                        <div style="color:#0689FB;" v-if="o.types && o.types===2">
                            <div style="display:flex;align-items:center;">
                                <div v-if="o.apply_status===0" class="failure">已取消</div>
                                <div v-if="o.apply_status===1" class="failure">等待用户确认</div>
                                <div v-if="o.apply_status===2" class="failure">已雇佣</div>
                                <div v-if="o.apply_status===2 && listType!=2" class="btn" @click="openWin('goOrder')">去订单</div>
                            </div>
                        </div>
                        <div v-else>
                            <div style="display:flex;align-items:center;">
                                <div v-if="o.apply_status===0" class="failure">已取消</div>
                                <div v-if="o.apply_status===1" class="btn" @click="confirmApply(o,i)">确认雇佣</div>
                                <div v-if="o.apply_status===1" class="btn" @click="cancelApply(o,i)">取消雇佣</div>
                                <div v-if="o.apply_status===2 && listType!=2" class="btn" @click="openWin('goOrder')">去订单</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            userInfo: {},

            list: [],
            listType: '',
            listPage: 1,
            listStatus: true,
        },
        methods: {
            init() {
                this.userInfo = get_local("userInfo");
                vm.listType = api.pageParam.type;
                this.upDownLoad();
                this.getList();
            },
            getList() {
                var that = this;
                var urls = {
                    1: Config.api.UserFoundUserSpecialtyApplyLists,
                    2: Config.api.UserFoundUserAmateurApplyLists
                };
                var data = {
                    work_id: api.pageParam.work_id,
                    pages: that.listPage
                };
                _ajax(urls[that.listType], data, function(ret) {
                    if (ret.code === 200) {
                        if (that.listPage === 1) {
                            that.list = ret.data;
                        } else {
                            if (ret.data.length > 0) {
                                that.list = that.list.concat(ret.data);
                            } else {
                                that.listStatus = false;
                            }
                        }
                    }
                });
            },
            openInfo(o) {
                var that = this;
                var winInfo = {
                    1: { //普通工人
                        name: 'ordinary_workers_win',
                        url: './ordinary_workers_win.html',
                        pageParam: {
                            id: o.apply_user_id,
                            isMobile: o.apply_status === 2
                        }
                    },
                    2: { //已认证工人
                        name: 'homepage_win',
                        url: '../../look_for_workers/homepage/homepage_win.html',
                        pageParam: {
                            id: o.apply_user_id,
                            isMobile: o.apply_status === 2,
                            hideFooter: true
                        }
                    }
                };
                open_w(winInfo[o.user_type].name, winInfo[o.user_type].url, winInfo[o.user_type].pageParam);
            },
            confirmApply(o, index) {
                var that = this;
                var urls = {
                    1: Config.api.UserFoundConfirmSpecialtyApply,
                    2: Config.api.UserFoundConfirmAmateurApply
                };
                var data = {
                    user_id: that.userInfo.user_id,
                    apply_id: o.apply_id,
                    apply_user_id: o.apply_user_id,
                    work_id: o.work_id,
                };

                _ajax(urls[that.listType], data, function(ret) {
                    if (ret.code === 200) {
                        $toast("雇佣成功");
                        that.list[index].apply_status = 2;
                        if (that.listType === 1) {
                            for (var i = 0; i < that.list.length; i++) {
                                if (i !== index) {
                                    that.list[i].apply_status = 0;
                                }
                            }
                        }
                    }
                });
            },
            cancelApply(o, index) {
                var that = this;
                var urls = {
                    1: Config.api.UserFoundCancelSpecialtyApply,
                    2: Config.api.UserFoundCancelAmateurApply
                };
                var data = {
                    user_id: that.userInfo.user_id,
                    apply_id: o.apply_id,
                    apply_user_id: o.apply_user_id,
                    work_id: o.work_id,
                };

                _ajax(urls[that.listType], data, function(ret) {
                    if (ret.code === 200) {
                        $toast("取消成功");
                        that.list[index].apply_status = 0;
                    }
                });
            },
            upDownLoad() {
                var that = this;

                // 下拉刷新
                push_down(function() {
                    //下拉刷新恢复
                    push_down_over();
                    that.listStatus = true;
                    that.listPage = 1;
                    that.getList();
                });

                //上拉加载
                push_up(function() {
                    if (that.listStatus) {
                        that.listPage++;
                        that.getList();
                    }
                });
            },
            openWin(name) {
                var winInfo = {
                    // 去订单
                    goOrder: {
                        name: 'hire_person_win',
                        url: '../../order/hire_person/hire_person_win.html'
                    }
                };
                if (name) {
                    open_w(winInfo[name].name, winInfo[name].url);
                } else {
                    $toast("正在开发中...");
                }
            }
        }
    });
</script>

</html>
